<template>
  <el-upload
    v-bind="$attrs"
    :on-success="onSuccess"
    :on-remove="onRemove"
    :headers="header"
    with-credentials
    :file-list="fileList"
    :disabled="type=='examine'|| type=='detail' || type =='approval' "
    list-type="picture-card">
    <i class="el-icon-plus"></i>
  </el-upload>
</template>

<script lang="ts">
import { Model, Prop, Vue } from 'vue-property-decorator'
import { getToken } from '@/utils/auth'
import { ObjectType } from 'typings/interfaces'
export default class FileUpload extends Vue {
  @Model('modelValue', { type: String, default: '' }) public value!: any
  @Prop({ type: Array })  fileList?: Array<ObjectType>
  @Prop({ type: String }) type!: string
  header = {Authorization: 'Bearer ' + getToken()}
  onSuccess(response){
    if(response?.code === 200 && response?.data?.fileId){
      this.value = response.data.fileId
    }
  }
  onError(){
    this.$message.error("上传失败")
  }
  onRemove(file, fileList){
    console.log(fileList)
    console.log(file)
    this.value = null
  }
}
</script>
